package taller2.controller.listeners.evaluateMeButtons;

import java.awt.event.ActionEvent;
import java.util.Random;

import taller2.controller.listeners.UserImputListener;
import taller2.interfaces.AlgorithmApplicator;
import taller2.interfaces.Graph;
import taller2.interfaces.Node;
import taller2.model.factorys.GraphFactory;
import taller2.model.graph.algorithms.FloydApplicator;
import taller2.utils.Constants;
import taller2.view.windows.UserImputWindow;

public class FloydEvaluateMeButtonListener extends EvaluateMeButtonListener{

	public FloydEvaluateMeButtonListener(AlgorithmApplicator aplicator) {
		super(aplicator);
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		menu.unselectButtons();
		FloydApplicator fl = (FloydApplicator)aplicator;

		Random rnd = new Random();
		int pos = rnd.nextInt(fl.getNodeCant());

		String path = fl.getGraphPath();
		if(path != null){
			Graph g = GraphFactory.directedGgraphInstance();
			g.load(path);
			Node intermediate = g.getNodeByIndex(pos);			

			String start = fl.getStartingMatrixUsingNode(pos);
			String sol = fl.getEndMatrixUsingNode(pos);
		

			String tag = intermediate.getTag();
			
			if (tag == null){
				tag = Constants.sinTag;
			}
			
			String msg = "si se itera a partir del nodo "+ tag +" que resultado arroja el algoritmo?";
			if(!start.isEmpty() && !sol.isEmpty())
				new UserImputWindow("Dada la siguiénte tabla",msg, start, sol, new UserImputListener());
		}
	}

}
